<?php
	include "../ini.php";
	include "../../libraries/xl_bai_viet.php";
	include "../../libraries/xl_loai_bai_viet.php";
	$dt_bai_viet = new xl_bai_viet;
	$dt_loai_bai_viet= new xl_loai_bai_viet;
		
		
	if (!isset($_GET['id']) || !is_numeric($_GET['id'])){
		$_SESSION['msg'] = "Lỗi! Dữ liệu  không hợp lệ, vui lòng kiểm tra lại";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;
	}
	$ma = $_GET['id'];
	$bai_viet = $dt_bai_viet->xem($ma);
	
	if($bai_viet == NULL){
		$_SESSION['msg'] = "Lỗi! Dữ liệu không tồn tại, vui lòng kiểm tra lại";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;
	}
	function in_ten_loai_cha($ds_loai_bai_viet,$ma, $kitu, $machon){
		foreach($ds_loai_bai_viet as $loai_bai_viet){
			if($loai_bai_viet['ma_loai_cha'] == $ma ){
				if($loai_bai_viet['ma'] == $machon){
					echo '<option selected="selected" value="'.$loai_bai_viet['ma'].'">'.$kitu.$loai_bai_viet['ten'].'</option>';
				}else{
					echo '<option value="'.$loai_bai_viet['ma'].'">'.$kitu.$loai_bai_viet['ten'].'</option>';
				}
				in_ten_loai_cha($ds_loai_bai_viet,$loai_bai_viet['ma'],$kitu.$kitu,$machon);
			}
		}
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include"../includes/js_css.php"?>
<style type="text/css">
#apDiv1 {
	position:absolute;
	left:740px;
	top:283px;
	width:130px;
	height:80px;
	z-index:1;
	border:#006 1px solid;
	text-align:center;
}
</style>
</head>
<body>

<div id="body-wrapper"> <!-- Wrapper for the radial gradient background -->
  
  <?php include"../widgets/sidebar.php"?>
  <!-- End #sidebar -->
  
  <div id="main-content"> <!-- Main Content Section with everything -->
    
    <?php include"../widgets/noscript.php"?>
    <div class="clear"></div>
    <!-- End .clear -->
    
    <div class="content-box"><!-- Start Content Box -->
      
      <div class="content-box-header">
        <h3>Cập nhật bài viết</h3>
        <div class="clear"></div>
      </div>
      <!-- End .content-box-header -->
      
      <div class="content-box-content"> 
        
        <!-- End #tab1 -->
        
        <div class="tab-content default-tab" id="tab2">
          <form name="f2" action="edit_sm.php" method="post"  enctype="multipart/form-data" >
          	<input type="hidden" name="ma" id="ma" value="<?php echo $bai_viet['ma'];?>"/>
            <fieldset>
              <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
              <table width="100%">
                <tbody>
                <div>
                  <?php message()?>
                </div>
                <tr class="alt-row">
                  <td width="23%">Tiêu đề</td>
                  <td width="73%"><input class="text-input medium-input datepicker" type="text" id="tieu_de" name="tieu_de"  value="<?php echo $bai_viet["tieu_de"];?>"/></td>
                </tr>
                <tr>
                  <td>Loại bài viết</td>
                  <td><select name="ma_loai" id="ma_loai" class="small-input" >
                     <?php 
						  $ds_loai_bai_viet = $dt_loai_bai_viet->danh_sach_all();
						  in_ten_loai_cha($ds_loai_bai_viet,0,'==',$bai_viet["ma_loai"]);
					  ?>   
                    </select></td>
                </tr>
                <tr class="alt-row">
                  <td>Ngày Đăng</td>
                  <td><script>
	$(function() {
		$( "#ngay_tao" ).datepicker({
			showOn: "button",
			buttonImage: "../images/calendar.gif",
			buttonImageOnly: true
		});
	});
	</script>
<div class="demo">

<input type="text"  class="text-input small-input" id="ngay_tao" name="ngay_tao" value="<?php echo $bai_viet["ngay_tao"];?>">

</div><!-- End demo -->
                    </td>
                </tr>
                <tr>
                  <td>Trạng Thái</td>
                  <td>
                  
                  <input type="radio" id="trang_thai" name="trang_thai" <?php if($bai_viet['trang_thai']==1) echo (" checked='checked'")?> value="1"/>
                    Hiện thị<br />
                    <input type="radio"  id="trang_thai" name="trang_thai" value="0"  <?php if($bai_viet['trang_thai']==0) echo (" checked='checked'")?>/>
                    Không hiện thị</td>
                </tr>
                <tr class="alt-row">
                  <td height="99">Hình Ảnh</td>
                  <td><input type="file" id="Hinh" name="Hinh"  class="text-input medium-input datepicker"/>
                  <br>*.gif , *.jpg ,*.png &lt; 2000kb)<br /><img width="100px" align="middle" src="../../uploads/bai_viet/<?php echo $bai_viet['hinh']?>" /> </td>
                
                </tr>
                <tr>
                  <td>Nội Dung Tóm Tắt</td>
                  <td><textarea class="text-input textarea " id="noi_dung_tom_tat" name="noi_dung_tom_tat" cols="79" rows="15"><?php echo $bai_viet['noi_dung_tom_tat']?></textarea>
                    <script type="text/javascript">
					CKEDITOR.replace( 'noi_dung_tom_tat',{
						sink :'kama',
						toolbar :[	
							['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
							['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
							['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
							['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
							['BidiLtr', 'BidiRtl' ],
							['Link','Unlink','Anchor'],
							['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
							'/',
							['Styles','Format','Font','FontSize'],
							['TextColor','BGColor'],
							['Maximize', 'ShowBlocks','-','About']]	});

			//]]>
			</script></td>
                </tr>
                <tr>
                  <td>Nội Dung Chi Tiết</td>
                  <td><textarea class="text-input textarea " id="noi_dung_chi_tiet" name="noi_dung_chi_tiet" cols="79" rows="15"><?php echo $bai_viet['noi_dung_chi_tiet']?></textarea>
                    <script type="text/javascript">
						CKEDITOR.replace( 'noi_dung_chi_tiet',{
							toolbar :[	
							['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
							['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
							['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
							['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
							['BidiLtr', 'BidiRtl' ],
							['Link','Unlink','Anchor'],
							['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
							'/',
							['Styles','Format','Font','FontSize'],
							['TextColor','BGColor'],
							['Maximize', 'ShowBlocks','-','About']]
						});
					</script></td>
                </tr>
                <tr>
                  <td style="text-align:center !important" colspan="2"><input class="button" type="submit" value="Lưu Và Thoát" name="luu_va_thoat">
                  <input class="button" type="button" value="Không lưu" onclick="window.location.href='list.php'"></td>
                </tr>
                  </tbody>
                
              </table>
            </fieldset>
            <div class="clear"></div>
            <!-- End .clear -->
            
          </form>
        </div>
        <!-- End #tab2 --> 
        
      </div>
      <!-- End .content-box-content --> 
      
    </div>
    <!-- End .content-box -->
    
    <div class="clear"></div>
    <?php include"../widgets/footer.php"?>
  </div>
  <!-- End #main-content --> 
  
</div>
</body>
</html>
